// pages/postsDetail/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        postId: "",
        postUserLike: null,
        posts: {
            userId: "",
            authorName: "1111",
            title: "ddddddddd",
            content: "ddddddddddddd",
            createTime: "2023-12-12 23:11:11",
            likeCount: 0,
            viewCount: 0,
            replyCount: 0,
        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log(options.postId)
        this.setData({
            postId: options.postId
        })
        this.init()
        wx.setNavigationBarTitle({
            title: "帖子详情"
          })
    },
    init() {
        let that = this
        wx.request({
            url: 'http://localhost:8080/system/wechat/posts/detail/' + that.data.postId,
            method: 'GET',
            dataType: 'json',
            success: resp => {
              this.setData({
                  posts: resp.data.data
              })
              that.getLike()
            }
          })
    },
    getLike() {
        let that = this
        wx.request({
            url: 'http://localhost:8080/system/wechat/post/like?userId=' + that.data.posts.userId + '&postId=' + that.data.posts.postId,
            method: 'GET',
            dataType: 'json',
            success: resp => {
              that.setData({
                  postUserLike: resp.data.data
              })
              console.log("that.data.postUserLike")
              console.log(that.data.postUserLike)
            }
          })
    },
    likeClick() {
        let that = this
        wx.request({
            url: 'http://localhost:8080/system/wechat/post/like',
            method: 'POST',
            dataType: 'json',
            data: {
                userId: that.data.posts.userId,
                postId: that.data.posts.postId,
                liked: 1
            },
            success: resp => {
                that.getLike()
            }
          })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})